﻿hpxAdminApp.controller('xingyeAccountController', function ($scope, $rootScope, $state, API_URL, NgTableParams, payingService, orderService, searchService) {
    var emptyEntity = {};
    var newEntity = angular.copy(emptyEntity, newEntity);

    $scope.filter = {
        'func': 'detail',
        'deadlineTime1': '',
        'deadlineTime2': ''
    };


    //获取所有兴业账户
    $scope.tableParams = new NgTableParams({ sorting: { 'id': 'asc' } }, {
        getData: function (params) {
            //console.log(params)
            return payingService.getAccountAll(params).then(function (data) {
                $scope.first = $scope.getFirst(params);
                //console.log(data)
                return data.accountList;
            });
        }
    });



    $scope.showlist = function (model) {
        $('#model-acctlist').modal('show');
        //console.log(model);
        $scope.tableParams1 = new NgTableParams({ sorting: { 'id': 'asc' } }, {
            getData: function (params) {
                //console.log("ss"+model);
                return model
            }

        });
    }

    $scope.deleteById = function (status,accountId) {
        //删除兴业账户
        if (confirm('确认删除此账户？')) {
            if (status != 1) {
                payingService.deleteById(accountId).then(function (data) {
                    //console.log(data);
                    $scope.tableParams.reload();
                });
            } else {
                alert("该账户状态不可删除");
            }
        }
    };

    // 删除绑定成功的银行卡
    $scope.deleteXingyeById = function (item) {
        if (confirm('确认删除此账户？')) {
            if (item.is_default == 1) {
                payingService.deleteXYById(item.account_id).then(function (data) {
                    $scope.tableParams.reload();
                });
            } else {
                alert("该账户是基本户，不可删除");
            }
        }
    }

    // 重新开户
    $scope.openAccount = function (item) {
        payingService.openAccountAdmin(item.enterprise_id,item).then(function (data) {
            alert("开户成功！");
        })
    }
});